﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

namespace YArchitech.HYSpace
{
	public class PropertyGridMgr : CollectionBase, ICustomTypeDescriptor
	{
		public void Add(PropertyGridItem value)
		{
			int num = -1;
			if (value != null)
			{
				if (base.List.Count > 0)
				{
					IList<PropertyGridItem> list = new List<PropertyGridItem>();
					for (int i = 0; i < base.List.Count; i++)
					{
						PropertyGridItem propertyGridItem = base.List[i] as PropertyGridItem;
						if (value.Name == propertyGridItem.Name)
						{
							num = i;
						}
						list.Add(propertyGridItem);
					}
					if (num == -1)
					{
						list.Add(value);
					}
					base.List.Clear();
					IEnumerator<PropertyGridItem> enumerator = list.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							PropertyGridItem value2 = enumerator.Current;
							base.List.Add(value2);
						}
						return;
					}
				}
				base.List.Add(value);
			}
		}

		public void Remove(PropertyGridItem value)
		{
			if (value != null && base.List.Count > 0)
			{
				base.List.Remove(value);
			}
		}

		public PropertyGridItem this[int index]
		{
			get
			{
				return (PropertyGridItem)base.List[index];
			}
			set
			{
				base.List[index] = value;
			}
		}

		public AttributeCollection GetAttributes()
		{
			return TypeDescriptor.GetAttributes(this, true);
		}

		public string GetClassName()
		{
			return TypeDescriptor.GetClassName(this, true);
		}

		public string GetComponentName()
		{
			return TypeDescriptor.GetComponentName(this, true);
		}

		public TypeConverter GetConverter()
		{
			return TypeDescriptor.GetConverter(this, true);
		}

		public EventDescriptor GetDefaultEvent()
		{
			return TypeDescriptor.GetDefaultEvent(this, true);
		}

		public PropertyDescriptor GetDefaultProperty()
		{
			return TypeDescriptor.GetDefaultProperty(this, true);
		}

		public object GetEditor(Type editorBaseType)
		{
			return TypeDescriptor.GetEditor(this, editorBaseType, true);
		}

		public EventDescriptorCollection GetEvents(Attribute[] attributes)
		{
			return TypeDescriptor.GetEvents(this, attributes, true);
		}

		public EventDescriptorCollection GetEvents()
		{
			return TypeDescriptor.GetEvents(this, true);
		}

		public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			PropertyDescriptor[] array = new PropertyDescriptor[base.Count];
			for (int i = 0; i < base.Count; i++)
			{
				PropertyGridItem propertyGridItem = this[i];
				array[i] = new CustomPropertyDescriptor(ref propertyGridItem, attributes);
			}
			return new PropertyDescriptorCollection(array);
		}

		public PropertyDescriptorCollection GetProperties()
		{
			return TypeDescriptor.GetProperties(this, true);
		}

		public object GetPropertyOwner(PropertyDescriptor pd)
		{
			return this;
		}
	}
}
